Generating a basic map image in Earth Engine

Install ee-python

Follow the installation directions found here:

https://github.com/catherinekuhn/CloudtoStreet/blob/master/Python%20API%20directions.ipynb

Check your environment

Make sure that you are in the correct environment. To check your current environment, type the following. The environment you are in will have a star next to it.

    conda info --envs

If you are not in the ee-python environment, you can switch into it using

    source activate ee-python

Import & Authentication


In [3]:
# Import the Earth Engine Python Package into Python environment.
import ee
import ee.mapclient

# Initialize the Earth Engine object, using the authentication credentials.
ee.Initialize()

Visualize Geographic Data


In [4]:
image = ee.Image('srtm90_v4')
from IPython.display import Image
Image(url=image.getThumbUrl({'min':0, 'max': 3000}))


Out[4]:

In [5]:
# Print the information for an image asset. the 'srtm90_v4 file is a digital elevation model. 
# that is housed in Google's cloud and has an elevation value for every pixel across the whole earth 
# at a resolution of 30 meters. That is the map you see below in the static notebook. 

print(image.getInfo())

#celebrate the metadata!!


{u'bands': [{u'crs': u'EPSG:4326', u'crs_transform': [0.0008333333535119891, 0.0, -180.0, 0.0, -0.0008333333535119891, 60.0], u'id': u'elevation', u'data_type': {u'max': 32767, u'type': u'PixelType', u'precision': u'int', u'min': -32768}, u'dimensions': [432000, 144000]}], u'version': 1427492341199000, u'type': u'Image', u'id': u'srtm90_v4', u'properties': {u'system:time_end': 951177600000, u'system:time_start': 950227200000}}

In [6]:
Irene= ee.Image("users/kuhniculous/floodwithnoletters")

from IPython.display import display,Image
test=ee.Image(Irene)

display(Image(url=test.select(['b1']).getThumbUrl({'gamma':2})))

Lparams = {
    'min':0.0134,
    'max':0.0338,
    'palette':'000000,0000ff,00ffff,00ff00,ffff00,ffa500,ff0000',
    };
display(Image(url=test.select(["b1"]).getThumbUrl(Lparams)))



In [7]:
Irene= ee.Image("users/kuhniculous/popImage")

from IPython.display import display,Image
test=ee.Image(Irene)

display(Image(url=test.select(['b1']).getThumbUrl({'gamma':2})))

Lparams = {
    'min':7,
    'max':7.5,
    'palette':'000000,ff0000',
    };
display(Image(url=test.select(["b1"]).getThumbUrl(Lparams)))


Try it with mapclient

This code will run but then nothing happens. I have no idea why!


In [10]:
"""Select rows from a fusion table."""

import ee
import ee.mapclient

ee.Initialize()
ee.mapclient.centerMap(-93, 40, 4)

# Select the 'Sonoran desert' feature from the TNC Ecoregions fusion table.

fc = (ee.FeatureCollection('ft:1Ec8IWsP8asxN-ywSqgXWMuBaxI6pPaeh6hC64lA')
      .filter(ee.Filter().eq('ECO_NAME', 'Sonoran desert')))

# Paint it into a blank image.
image1 = ee.Image(0).mask(0)
ee.mapclient.addToMap(image1.paint(fc, 0, 5))

Testing Out Jill's Method for Displaying Maps


In [11]:
%matplotlib inline

from __future__ import print_function # For py 2.7 compat

import datetime
from IPython.html import widgets
from IPython.display import display
from IPython.utils import traitlets
from IPython.core.display import Javascript

In [12]:
%run 'define_google_maps_interactive_widget.ipynb'


/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:2: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  from ipykernel import kernelapp as app
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:3: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
  app.launch_new_instance()
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:4: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:5: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:6: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:7: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipykernel/__main__.py:8: DeprecationWarning: metadata {'sync': True} was set from the constructor.  Metadata should be set using the .tag() method, e.g., Int().tag(key1='value1', key2='value2')

In [13]:
Irene= ee.Image("users/kuhniculous/popImage")

In [14]:
map = GoogleMapsWidget(lat=59.5, lng=10.9, zoom=13) # lat, lng and zoom are optional
display(map)

map.addLayer(Irene, {'color': 'FFFFCC'}, name='Irene Map')


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    905             method = _safe_get_formatter_method(obj, self.print_method)
    906             if method is not None:
--> 907                 method()
    908                 return True
    909 

/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in _ipython_display_(self, **kwargs)
    444         # Show view.
    445         if self._view_name is not None:
--> 446             self._send({"method": "display"})
    447             self._handle_displayed(**kwargs)
    448 

/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in _send(self, msg, buffers)
    449     def _send(self, msg, buffers=None):
    450         """Sends a message to the model in the front-end."""
--> 451         self.comm.send(data=msg, buffers=buffers)
    452 
    453 

AttributeError: 'NoneType' object has no attribute 'send'
<__main__.GoogleMapsWidget at 0x10c32d3d0>
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-fd002bb293db> in <module>()
      2 display(map)
      3 
----> 4 map.addLayer(Irene, {'color': 'FFFFCC'}, name='Irene Map')

<ipython-input-12-5f10f8a4a45d> in addLayer(self, image, vis_params, name, visible)
     15     def addLayer(self, image, vis_params, name=None, visible=True):
     16         mapid = image.getMapId(vis_params)
---> 17         self.send({'command':'addLayer', 'mapid': mapid['mapid'], 'token': mapid['token'], 'name': name, 'visible': visible})
     18 
     19     def center(self, lng, lat, zoom=None):

/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in send(self, content, buffers)
    295             Binary buffers to send with message
    296         """
--> 297         self._send({"method": "custom", "content": content}, buffers=buffers)
    298 
    299     def on_msg(self, callback, remove=False):

/Users/catherinekuhn/miniconda2/envs/ee-python/lib/python2.7/site-packages/ipywidgets/widgets/widget.pyc in _send(self, msg, buffers)
    449     def _send(self, msg, buffers=None):
    450         """Sends a message to the model in the front-end."""
--> 451         self.comm.send(data=msg, buffers=buffers)
    452 
    453 

AttributeError: 'NoneType' object has no attribute 'send'